// pages/recommend/recommend.js
const {getSwipers, getHotAlbum} = require('../../service/recommend.js')

Page({
  data: {
    swiperList: [],
    albums: []
  },
  async onLoad() {
    wx.showLoading({title: '加载中'})
    const res = (await getSwipers()).data
    const albums = (await getHotAlbum()).data
    this.setData({
      swiperList: res.banners.slice(0, 7),
      albums: albums.playlists
    }, () => wx.hideLoading())
  },
  // 点击单个推荐
  selectItem({currentTarget: {dataset: {item}}}) {
    const {name, id, coverImgUrl: pic} = item
    const params = {name, id, pic}
    wx.navigateTo({
      url: `../album/album?album=${encodeURIComponent(JSON.stringify(params))}`
    })
  }
})